//
//  EventDetailVC.m
//  ConvenientlyTake
//
//  Created by 森鑫 on 2022/12/22.
//

#import "EventDetailVC.h"
#import "EvenDetailBottomView.h"
#import "EventDetailBaseCell.h"
#import "EventDetailBaseCell2.h"
#import "EventDetailQuestionDescCell.h"
#import "EventDetailImageViewCell.h"
#import "EventDetailVideoCell.h"
#import "EventDisposeVC.h"
#import "EvenReviewVC.h"
#import "EventLogCell.h"
#import "EventDetailAPIRequest.h"
#import "EventDetailModel.h"


#import "EventAssignManagerVC.h"
#import "EventAssignDeptVC.h"
#import "EventAssignUserVC.h"

@interface EventDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UIView*topView;
@property(nonatomic,strong)UIImageView*topImageView;
@property(nonatomic,strong)UILabel*topTitleLab;

@property(nonatomic,strong)UITableView*tableview;
@property(nonatomic,strong)NSMutableArray*dataArray;
//
@property(nonatomic,strong)NSMutableArray *footArray;
@property(nonatomic,strong)NSArray *statusImageArray;

@property (nonatomic , strong) UIView *bottomView;
@property (nonatomic , strong) UIView *contentView;

@property(nonatomic,strong)EventDetailModel*detailsModel;
@property(nonatomic,strong) NSMutableArray *logModelArray;
//事件状态(1-待受理; 2-指派中；3-处理中；4-局委审核中；5-宣传部审核中;6-已办结;7-不予受理)

@end

@implementation EventDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"事件详情";
    [self requestData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestData) name:KNotificationWithRefresheEventDetailVC object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
   
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    [self setNavStyleWhiteAndBackBtn];
}

- (void)requestData{
    [TGProgressHUD showHUD:nil];
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_group_t group = dispatch_group_create();

        dispatch_group_enter(group);
        dispatch_group_async(group, queue, ^{
           
            [EventDetailAPIRequest GETEventDetailsWithEventId:self.eventId success:^(TGResponseItem *responseItem) {
                if (responseItem.success) {
                    self.detailsModel = [EventDetailModel modelWithJSON:responseItem.data];
                    dispatch_group_leave(group);
                }
            } fail:^(NSError *error) {
                dispatch_group_leave(group);
            }];
        });

        dispatch_group_enter(group);
        dispatch_group_async(group, queue, ^{
            [EventDetailAPIRequest GETEventLogWithEventId:self.eventId success:^(TGResponseItem *responseItem) {
               
                if (responseItem.success) {
                    self.logModelArray = [NSMutableArray array];
                    self.logModelArray = [NSArray modelArrayWithClass:[EventLogModel class] json:responseItem.data].mutableCopy;
                    dispatch_group_leave(group);
                }
            } fail:^(NSError *error) {
                dispatch_group_leave(group);
            }];
        });

        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            [TGProgressHUD dismissMPHUD];
            [self initContentView];
            if (self.logModelArray.count > 0) {
                [self.dataArray addObject:self.logModelArray];
                [self.footArray addObject:@""];
            }
            [self.tableview reloadData];
        });
}

- (void)initContentView{
    [self.view addSubview:self.topView];
    [self.view addSubview:self.bottomView];
    [self.topView addSubview:self.topImageView];
    [self.topView addSubview:self.topTitleLab];
    [self.view addSubview:self.tableview];
    // 不予受理
    /**按钮权限判断*/
//    self.bottomView.leftBtn.hidden = YES;
//    self.bottomView.rightBtn.hidden = YES;
    self.bottomView.hidden = YES;
    [self.bottomView removeAllSubviews];
    if (self.detailsModel.eventState == 7) {
        [self configRejectArray:self.detailsModel];
    } else {
        [self configCellItem];
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:self.detailsModel.operations.count];
        for (OperationsModel *item in self.detailsModel.operations) {
            if (![item.code isEqualToString:@"close"]) {
                EventDetailCustomBtn * btn = [[EventDetailCustomBtn alloc] init];
                btn.identifireString = item.code;
                [btn addTarget:self action:@selector(selelctItemSender:) forControlEvents:UIControlEventTouchUpInside];
                [btn setTitle:item.name forState:UIControlStateNormal];
                btn.layer.cornerRadius = 4;
                [self.bottomView addSubview:btn];
                if ([item.code isEqualToString:@"assignReject"]){
                    [btn setTitle:@"驳回" forState:UIControlStateNormal];
                    [array insertObject:btn atIndex:0];
                } else{
                    [array addObject:btn];
                }
            }
        }
        CGFloat width = 0;
        if (array.count > 0) {
            self.bottomView.hidden = NO;
            width = (SCREEN_WIDTH - 32 - (array.count - 1) * 12 ) / array.count;
        }
        for (int i = 0; i < array.count; i++) {
            EventDetailCustomBtn *item = array[i];
            if(array.count == 1) {
                item.backgroundColor = RGBA(22, 93, 255, 1);
                [item setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            } else {
                if (i == 0) {
                    item.backgroundColor = [UIColor whiteColor];
                    [item setTitleColor: RGBA(22, 93, 255, 1) forState:UIControlStateNormal];
                    item.layer.borderWidth = 1;
                    item.layer.borderColor = RGBA(22, 93, 255, 1).CGColor;
                } else {
                    item.backgroundColor = RGBA(22, 93, 255, 1);
                    [item setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                }
            }
            [item setFrame:CGRectMake(16 + i * (width + 12), 10, width, 44)];
        }
    }
        /**不予处理**/
//        if ([array containsObject:@"close"]) {
//
//        }
//        if ([array containsObject:@"assign"]){
//            self.bottomView.hidden = NO;
//            NSInteger index = [array indexOfObject:@"assign"];
//            OperationsModel *item = [self.detailsModel.operations objectAtIndex:index];
//            self.bottomView.rightBtn.hidden = NO;
//            self.bottomView.rightBtn.identifireString = item.code;
//            [self.bottomView.rightBtn setTitle:item.name forState:UIControlStateNormal];
//        }
//        if ([array containsObject:@"assignReject"]){
//            self.bottomView.hidden = NO;
//            NSInteger index = [array indexOfObject:@"assignReject"];
//            OperationsModel *item = [self.detailsModel.operations objectAtIndex:index];
//            self.bottomView.leftBtn.hidden = NO;
//            self.bottomView.leftBtn.identifireString = item.code;
//            [self.bottomView.leftBtn setTitle:item.name forState:UIControlStateNormal];
//        }
//        if ([array containsObject:@"disposal"]){
//            self.bottomView.hidden = NO;
//            NSInteger index = [array indexOfObject:@"disposal"];
//            OperationsModel *item = [self.detailsModel.operations objectAtIndex:index];
//            self.bottomView.rightBtn.hidden = NO;
//            self.bottomView.rightBtn.identifireString = item.code;
//            [self.bottomView.rightBtn setTitle:item.name forState:UIControlStateNormal];
//        }
//        if ([array containsObject:@"audit"]){
//            self.bottomView.hidden = NO;
//            NSInteger index = [array indexOfObject:@"audit"];
//            OperationsModel *item = [self.detailsModel.operations objectAtIndex:index];
//            self.bottomView.rightBtn.hidden = NO;
//            self.bottomView.rightBtn.identifireString = item.code;
//            [self.bottomView.rightBtn setTitle:item.name forState:UIControlStateNormal];
//        }
//    }
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(self.bottomView.hidden?(IS_IPHONEX?20:0):102);
    }];
    [self setUIFrame];
}
- (void)configCellItem{
    self.topView.backgroundColor= [self getEventStateBgColor];
    self.topImageView.image=[UIImage imageNamed:self.statusImageArray[self.detailsModel.eventState]];
    self.topTitleLab.textColor=[self getEventStateTextColor];
    self.topTitleLab.text=self.detailsModel.eventStateName;
    self.dataArray = [NSMutableArray array];
    NSMutableArray *customArray = @[@"事件单号",@"当前处置部门",@"要求处置时间",@"处置完成时间",@"办结时间"].mutableCopy;
    if (!self.detailsModel.disposeCompletionTime) {
        [customArray removeObject:@"处置完成时间"];
    }
    if (!self.detailsModel.completionTime) {
        [customArray removeObject:@"办结时间"];
    }
    [self.dataArray addObject:customArray];
    if(self.detailsModel.showState){
        NSMutableArray *arra1 = @[@"处置人",@"处置意见",@"处置图片",@"提交时间"].mutableCopy;
        if (self.detailsModel.disposePictureList.count == 0) {
            [arra1 removeObject:@"处置图片"];
        }
        self.footArray = @[@"处置信息" , @"反映信息", @"操作日志" ,@""].mutableCopy;
        [self.dataArray addObject:arra1];
    } else {
        self.footArray = @[@"反映信息", @"操作日志" ,@""].mutableCopy;
    }
    NSMutableArray *array = @[@"发起人",@"联系方式",@"事件类型",@"问题描述",@"反映图片",@"视频",@"发起时间",@"发生地点"].mutableCopy;
    if (self.detailsModel.resultPictureList.count == 0) {
        [array removeObject:@"反映图片"];
    }
    if (self.detailsModel.resultVideoList.count == 0) {
        [array removeObject:@"视频"];
    }
    [self.dataArray addObject:array];
}
//   不予受理
-(void)configRejectArray:(id)detailsModel{
    self.topView.backgroundColor= [self getEventStateBgColor];
    self.topImageView.image=[UIImage imageNamed:self.statusImageArray[self.detailsModel.eventState]];
    self.topTitleLab.textColor=[self getEventStateTextColor];
    self.topTitleLab.text=self.detailsModel.eventStateName;
    
    self.dataArray = [NSMutableArray array];
    NSMutableArray *customArray = @[@"事件单号",@"当前处置部门",@"要求处置时间",@"处置完成时间",@"办结时间"].mutableCopy;
    if (!self.detailsModel.disposeCompletionTime) {
        [customArray removeObject:@"处置完成时间"];
    }
    if (!self.detailsModel.completionTime) {
        [customArray removeObject:@"办结时间"];
    }
    [self.dataArray addObject:customArray];
    NSMutableArray *arra1 = @[@"操作人",@"意见",@"不予受理图片",@"提交时间"].mutableCopy;
    if (self.detailsModel.noDisposalPictureList.count == 0) {
        [arra1 removeObject:@"不予受理图片"];
    }
    [self.dataArray addObject:arra1];
    NSMutableArray *array = @[@"发起人",@"联系方式",@"事件类型",@"问题描述",@"反映图片",@"视频",@"发起时间",@"发生地点"].mutableCopy;
    if (self.detailsModel.resultPictureList.count == 0) {
        [array removeObject:@"反映图片"];
    }
    if (self.detailsModel.resultPictureList.count == 0) {
        [array removeObject:@"视频"];
    }
    [self.dataArray addObject:array];
    self.footArray = @[@"不予受理信息" , @"反映信息", @"操作日志" , @""].mutableCopy;
    self.bottomView.hidden = YES;
    [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(IS_IPHONEX?20:0);
    }];
}

#pragma mark -  (按钮)单击事件-----------(按钮)单击事件-----------
- (void)selelctItemSender:(EventDetailCustomBtn *)sender{
   
   
    if ([sender.identifireString isEqualToString :@"assign"]){
        for (OperationsModel *item in self.detailsModel.operations) {
            if ([item.code isEqualToString:@"assign"]){
                Metadata *mm = item.metadata;
                if (mm.allowToAssignDept && mm.allowToAssignUser) {
                    EventAssignManagerVC *vc = [[EventAssignManagerVC alloc] init];
                    vc.eventId = self.eventId;
                    vc.deptId = self.detailsModel.disposalDeptId;
                    vc.assignTaskId = mm.assignTaskId;
                    [self pushViewController:vc complent:nil];
                }else if (mm.allowToAssignDept){
                    EventAssignDeptVC*vc = [[EventAssignDeptVC alloc] init];
                    vc.eventId = self.eventId;
                    vc.showBottomView = YES;
                    vc.deptId = self.detailsModel.disposalDeptId;
                    vc.assignTaskId = mm.assignTaskId;
                    [self pushViewController:vc complent:nil];
                } else if (mm.allowToAssignUser) {
                    EventAssignUserVC *vc = [[EventAssignUserVC alloc] init];
                    vc.eventId = self.eventId;
                    vc.deptId = self.detailsModel.disposalDeptId;
                    vc.showBottomView = YES;
                    vc.assignTaskId = mm.assignTaskId;
                    [self pushViewController:vc complent:nil];
                }
                break;
            }
        }
    }
    // 指派驳回
    if ([sender.identifireString isEqualToString :@"assignReject"]){
        [self alertRejectWithBlock:^(NSString *reason) {
            [self rejectActionWithReason:reason];
        }];
    }
    // 处置
    if ([sender.identifireString isEqualToString :@"disposal"]){
        EventDisposeVC *vc = [[EventDisposeVC alloc] init];
        vc.eventId = self.eventId;
        [self pushViewController:vc complent:nil];
    }
    // 审核
    if ([sender.identifireString isEqualToString :@"audit"]){
        for (OperationsModel *item in self.detailsModel.operations) {
            if([item.code isEqualToString:@"audit"]){
                EvenReviewVC *vc = [[EvenReviewVC alloc] init];
                vc.auditTaskId = item.metadata.auditTaskId;
                [self pushViewController:vc complent:nil];
                break;
            }
        }
    }
}
#pragma mark - 驳回事件
- (void)rejectActionWithReason:(NSString *)reason {
    // 只调用指派驳回
    [TGProgressHUD showHUD:nil];
    [EventDetailAPIRequest POSTworkingAssignRejectWithEventId:self.eventId rejectionReason:reason success:^(TGResponseItem *responseItem) {
        [TGProgressHUD dismissMPHUD];
        if (responseItem.success) {
            [[NSNotificationCenter defaultCenter] postNotificationName:KNotificationWithRefresheEventCenterVC object:nil];
            [self.navigationController popViewControllerAnimated:YES];
        }
    } fail:^(NSError *error) {
        [TGProgressHUD dismissMPHUD];
    }];
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *array  = [self.dataArray objectAtIndex:indexPath.section];
    id objc = array[indexPath.row];
    if ([objc isKindOfClass:[NSString class]]) {
        NSString *titleString = [array objectAtIndex:indexPath.row];
        if ([titleString isEqualToString:@"发起人"]) {
            EventDetailBaseCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"EventDetailBaseCell2" forIndexPath:indexPath];
            if (array.count - 1 == indexPath.row) {
                cell.lineView.hidden = YES;
            } else {
                cell.lineView.hidden = NO;
            }
            [cell fillDataWith:self.detailsModel andTitleString:titleString];
            return cell;
        } else if ([titleString isEqualToString:@"问题描述"] || [titleString isEqualToString:@"处置意见"] || [titleString isEqualToString:@"意见"]) {
            EventDetailQuestionDescCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventDetailQuestionDescCell" forIndexPath:indexPath];
            if (array.count - 1 == indexPath.row) {
                cell.lineView.hidden = YES;
            } else {
                cell.lineView.hidden = NO;
            }
            [cell fillDataWith:self.detailsModel andTitleString:titleString];
            return cell;
        } else if ([titleString isEqualToString:@"处置图片"] || [titleString isEqualToString:@"反映图片"]) {
            EventDetailImageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventDetailImageViewCell" forIndexPath:indexPath];
            if (array.count - 1 == indexPath.row) {
                cell.lineView.hidden = YES;
            } else {
                cell.lineView.hidden = NO;
            }
            if ([titleString isEqualToString:@"处置图片"]) {
                [cell fillDataWith:self.detailsModel andTitleString:titleString andImageArray:self.detailsModel.disposePictureList];
            } else if ([titleString isEqualToString:@"反映图片"]) {
                [cell fillDataWith:self.detailsModel andTitleString:titleString andImageArray:self.detailsModel.resultPictureList];
            }else if ([titleString isEqualToString:@"不予受理图片"]) {
                [cell fillDataWith:self.detailsModel andTitleString:titleString andImageArray:self.detailsModel.resultPictureList];
            }
            return cell;
        } else if ([titleString isEqualToString:@"视频"]) {
            EventDetailVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventDetailVideoCell" forIndexPath:indexPath];
            if (array.count - 1 == indexPath.row) {
                cell.lineView.hidden = YES;
            } else {
                cell.lineView.hidden = NO;
            }
            [cell fillDataWith:self.detailsModel andTitleString:titleString];
            return cell;
        } else {
            EventDetailBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventDetailBaseCell" forIndexPath:indexPath];
            if (array.count - 1 == indexPath.row) {
                cell.lineView.hidden = YES;
            } else {
                cell.lineView.hidden = NO;
            }
            [cell fillDataWith:self.detailsModel andTitleString:titleString];
            return cell;
        }
    } else if ([objc isKindOfClass:[EventLogModel class]]) {
        EventLogCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventLogCell" forIndexPath:indexPath];
        cell.indexPath = indexPath;
        cell.dataArray = [self.logModelArray copy];
        [cell fillDataWith:self.logModelArray[indexPath.row] andTitleString:@""];
        return cell;
    }
    return [UITableViewCell new];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *array  = self.dataArray[section];
    return array.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.dataArray.count;;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array  = [self.dataArray objectAtIndex:indexPath.section];
    id objc = array[indexPath.row];
    if ([objc isKindOfClass:[NSString class]]) {
        NSString *titleString = [array objectAtIndex:indexPath.row];
        if ([titleString isEqualToString:@"反映图片"]) {
            NSInteger count = ceil((self.detailsModel.resultPictureList.count)/4.0);
            return  PhotoCollectionViewHeight(count) + 61;
        } else if ([titleString isEqualToString:@"视频"]) {
            NSInteger count = ceil((self.detailsModel.resultVideoList.count)/4.0);
            return  PhotoCollectionViewHeight(count) + 61;
        } else if ([titleString isEqualToString:@"处置图片"]) {
            NSInteger count = ceil((self.detailsModel.disposePictureList.count)/4.0);
            return  PhotoCollectionViewHeight(count) + 61;
        }  else if ([titleString isEqualToString:@"不予受理图片"]) {
            NSInteger count = ceil((self.detailsModel.noDisposalPictureList.count)/4.0);
            return  PhotoCollectionViewHeight(count) + 61;
        } else {
            return  UITableViewAutomaticDimension;
        }
    } else if ([objc isKindOfClass:[EventLogModel class]]) {
        EventLogModel *model =  (EventLogModel*)objc;
        if (model.serviceFileList.count > 0) {
            if ([model.eventName isEqualToString:@"不予受理"]) {
                CGFloat height = [model.problemDescription heightForFont:TGAutoFont(14) width:SCREEN_WIDTH - 35 - 16 - 80];
                NSInteger count = ceil((model.photoArray.count)/4.0);
                return  PhotoCollectionViewHeight(count) + 129 + height;
            } else if ([model.eventName isEqualToString:@"处置审核"]) {
                CGFloat height = [model.remark heightForFont:TGAutoFont(14) width:SCREEN_WIDTH - 35 - 16 - 80];
                NSInteger count = ceil((model.photoArray.count)/4.0);
                return  PhotoCollectionViewHeight(count) + 185 + height;
            } else{
                CGFloat height = [model.remark heightForFont:TGAutoFont(14) width:SCREEN_WIDTH - 35 - 16 - 80];
                NSInteger count = ceil((model.photoArray.count)/4.0);
                return  PhotoCollectionViewHeight(count) + 153 + height;
            }
        } else {
            return UITableViewAutomaticDimension;
        }
    }
    return  UITableViewAutomaticDimension;
}



-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return  [[UIView alloc] initWithFrame:CGRectZero];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
    
}


-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSString *string = [self.footArray objectAtIndex:section];
    if (string.length > 0) {
        UIView *view = [[UIView alloc] init];
        [view setFrame:CGRectMake(0, 0,SCREEN_WIDTH, 48)];
        view.backgroundColor = UIColorForBackground;
        UILabel *label  = [[UILabel alloc] init];
        [label setFrame:CGRectMake(16, 0, SCREEN_WIDTH - 32, 48)];
        label.text = string;
        label.textColor = RGBA(133, 144, 156, 1);
        label.font = TGAutoFont(14);
        [view addSubview:label];
        return view;
    } else {
        return  [[UIView alloc] initWithFrame:CGRectZero];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    NSString *string = [self.footArray objectAtIndex:section];
    if (string.length > 0) return 48;
    return 0;
}


-(UIColor *)getEventStateTextColor {
    if (self.detailsModel.eventState == 1) {
        //待受理
        return RGB(134, 144, 156);
    } else if (self.detailsModel.eventState == 2 || self.detailsModel.eventState == 3 || self.detailsModel.eventState == 4 || self.detailsModel.eventState == 5)  {
        //指派中 || 处理中 || 审核中
        return RGB(22, 93, 255);
    } else if (self.detailsModel.eventState == 6) {
        //已办结
        return RGB(0, 180, 42);
    } else if (self.detailsModel.eventState == 7) {
        //不予受理
        return RGB(255, 135, 0);
    } else {
        //默认灰色
        return RGB(134, 144, 156);
    }
}

- (UIColor *)getEventStateBgColor {
    if (self.detailsModel.eventState == 1) {
        //待受理
        return RGB(242, 243, 245);
    } else if (self.detailsModel.eventState == 2 || self.detailsModel.eventState == 3 || self.detailsModel.eventState == 4 || self.detailsModel.eventState == 5) {
        //指派中 || 处理中 || 审核中
        return RGB(232, 243, 255);
    } else if (self.detailsModel.eventState == 6) {
        //已办结
        return RGB(232, 255, 234);
    } else if (self.detailsModel.eventState == 7) {
        //不予受理
        return RGB(255, 247, 232);
    } else {
        //默认灰色
        return RGB(242, 243, 245);
    }
}
#pragma mark -  (UI)懒加载------------ (UI)懒加载------------
-(UIView *)topView{
    if (!_topView){
        _topView=[[UIView alloc]init];
    }
    return _topView;
}
-(UIImageView *)topImageView{
    if (!_topImageView){
        _topImageView=[[UIImageView alloc]init];
        _topImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _topImageView;
}
-(UILabel *)topTitleLab{
    if (!_topTitleLab){
        _topTitleLab=[[UILabel alloc]init];
        _topTitleLab.font=TGAutoFont(14);
        _topTitleLab.textAlignment = NSTextAlignmentLeft;
    }
    return _topTitleLab;
}
-(UITableView*)tableview{
    if (!_tableview){
        _tableview=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate=self;
        _tableview.dataSource=self;
        _tableview.backgroundColor=UIColorForBackground;
        _tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableview.showsVerticalScrollIndicator=NO;
        _tableview.estimatedRowHeight = 54;
        _tableview.rowHeight=UITableViewAutomaticDimension;
        [_tableview registerNib:[UINib nibWithNibName:@"EventDetailBaseCell" bundle:nil] forCellReuseIdentifier:@"EventDetailBaseCell"];
        [_tableview registerNib:[UINib nibWithNibName:@"EventDetailBaseCell2" bundle:nil] forCellReuseIdentifier:@"EventDetailBaseCell2"];
        [_tableview registerNib:[UINib nibWithNibName:@"EventDetailQuestionDescCell" bundle:nil] forCellReuseIdentifier:@"EventDetailQuestionDescCell"];
        [_tableview registerNib:[UINib nibWithNibName:@"EventDetailVideoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EventDetailVideoCell"];
        [_tableview registerNib:[UINib nibWithNibName:@"EventDetailImageViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EventDetailImageViewCell"];
        [_tableview registerNib:[UINib nibWithNibName:@"EventLogCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"EventLogCell"];
//        [_tableview hideFooter];
//        [_tableview startPullDown];
    }
    return _tableview;
}

- (NSArray *)statusImageArray{
    if(!_statusImageArray) {
        _statusImageArray = @[@"event_waiting" , @"event_waiting" , @"event_beingProcessed" , @"event_beingProcessed" , @"event_beingProcessed" , @"event_beingProcessed",@"event_completion",@"event_reject"];
    }
    return _statusImageArray;
}

- (UIView *)bottomView{
    if(!_bottomView){
//        _bottomView = [[[NSBundle mainBundle] loadNibNamed:@"EvenDetailBottomView" owner:self options:0] firstObject];
//        _bottomView.delegate = self;
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

#pragma mark -  页面布局------------页面布局------------
-(void)setUIFrame{
   
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view).offset(0);
        make.height.mas_equalTo(RatioWidth(36));
    }];
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topView.mas_left).offset(RatioWidth(16));
        make.centerY.equalTo(self.topView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [self.topTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self.topView).offset(0);
        make.left.equalTo(self.topImageView.mas_right).offset(RatioWidth(3));
        
    }];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view).offset(0);
        make.top.equalTo(self.topView.mas_bottom).offset(0);
        make.bottom.equalTo(self.bottomView.mas_top).offset(0);
    }];
    _tableview.ly_emptyView = [MyEmptyView emptyWithContentViewDetailStr:@"暂时没有记录哦！" imageStr:@"empty_nodata" btnClickBlock:nil configerBlock:^(MyEmptyView *configer) {
        configer.contentViewOffset = -RatioHeight(50);
        configer.imageSize = CGSizeMake(RatioWidth(200), RatioWidth(200));
    }];
  
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)alertRejectWithBlock:(void(^)(NSString *reason))block{
    LEEActionSheetConfig *alert = [LEEAlert actionsheet];
    QMUITextView *textView = [[QMUITextView alloc] initWithFrame:CGRectMake(RatioWidth(10), 48, SCREEN_WIDTH - RatioWidth(20), RatioWidth(180))];
    textView.textColor = DeepBlackColor;
    textView.font = TGAutoFont(16);
    textView.placeholder = @"请输入";
    textView.contentInset = UIEdgeInsetsMake(0, 5, 5, 5);
    textView.placeholderColor = LightGrayColor;
    textView.backgroundColor = [UIColor whiteColor];
    textView.layer.cornerRadius = TableViewCornerRadius;
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, RatioWidth(266))];
    self.contentView = contentView;
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 28)];
    [contentView addSubview:topView];
    [contentView addSubview:textView];
    
    QMUIButton *cancelBtn = [[QMUIButton alloc] init];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:RGBA(134, 144, 156, 1) forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = TGAutoFont(16);
    [topView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.bottom.mas_equalTo(0);
    }];
    [cancelBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id  _Nonnull sender) {
        [LEEAlert closeWithIdentifier:@"close_reject" completionBlock:^{
            
        }];
    }];
    
    QMUIButton *sureBtn = [[QMUIButton alloc] init];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [sureBtn setTitleColor:GlobalBarBlueTinColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = TGAutoFont(16);
    [topView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.bottom.mas_equalTo(0);
    }];
    [sureBtn addBlockForControlEvents:UIControlEventTouchUpInside block:^(id  _Nonnull sender) {
        if (textView.text.length == 0) {
            [TGProgressHUD showHUDTip:@"请输入驳回原因"];
            return;
        }
        if (block){
            block(textView.text);
        }
        [LEEAlert closeWithIdentifier:@"close_reject" completionBlock:^{
            
        }];
    }];
    
    QMUILabel *titleLabel = [[QMUILabel alloc] init];
    titleLabel.text = @"驳回原因";
    titleLabel.textColor = RGBA(29, 33, 41, 1);
    titleLabel.font = [TG_UIHelper TGAutoFount:18 name:Ping_Medium];
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(topView.mas_centerX);
        make.centerY.mas_equalTo(topView.mas_centerY);
    }];
    
    alert.config
    .LeeMaxWidth(SCREEN_WIDTH)
//    .LeeMaxHeight(RatioWidth(300))
    .LeeStatusBarStyle(UIStatusBarStyleLightContent)
    .LeeIdentifier(@"close_reject")
    .LeeAddCustomView(^(LEECustomView *custom) {
        custom.view = contentView;
        custom.positionType = LEECustomViewPositionTypeCenter;
    })
    .LeeActionSheetBottomMargin(0.0) // 设置底部距离屏幕的边距
    .LeeActionSheetBackgroundColor([UIColor whiteColor])
    .LeeCornerRadii(CornerRadiiMake(10, 10, 0, 0))   // 指定整体圆角半径
    .LeeAvoidKeyboard(YES)
    .LeeShow();
}

-(void)showKeyboard:(NSNotification *)notification
{
    //键盘出现后的位置
    CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyboardHeight = endFrame.size.height;
    //键盘弹起时的动画效果
    UIViewAnimationOptions option = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] intValue];
    //键盘动画时长
    NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    __block typeof(self)weakSelf = self;
    
    [UIView animateWithDuration:duration delay:0 options:option animations:^{
        [self.contentView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, RatioWidth(266) + keyboardHeight)];
    } completion:nil];
    
}
#pragma mark --- 收起键盘
-(void)hideKeyboard:(NSNotification *)notification
{
    NSLog(@"收起键盘");
    UIViewAnimationOptions option = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] intValue];
    NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    __weak typeof(self)weakSelf = self;
    [UIView animateWithDuration:duration delay:0 options:option animations:^{
        [self.contentView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, RatioWidth(266))];
    } completion:^(BOOL finished) {
        
    }];
}

@end
